#include "chatrecord.h"
#include "ui_chatrecord.h"
#include "clientdatabase.h"
#include <QMouseEvent>

chatRecord::chatRecord(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::chatRecord)
{
    ui->setupUi(this);
    QString s="群聊聊天记录";
    ui->label->setText(s);
    clientDataBase::getInstance()->show_group_chatrecord(sr);
     this->setWindowFlags(Qt::FramelessWindowHint);
    for(int i=0;i<sr.size();i++){
        QString s=sr[i];
        ui->textEdit->append(s);
    }

}

chatRecord::chatRecord(const QString&selfname,const QString&friname,const QString&selfaccount,const QString&friaccount):
     ui(new Ui::chatRecord)
{
    QWidget *parent = nullptr;
    ui->setupUi(this);
    QString s=selfname+"和"+friname+"的聊天记录";
    ui->label->setText(s);
    clientDataBase::getInstance()->show_single_chatrecord(sr,selfaccount,friaccount);
    for(int i=0;i<sr.size();i++){
        qDebug()<<"聊天记录"<<endl;
        qDebug()<<sr[i]<<endl;
        QString s=sr[i];
        ui->textEdit->append(s);
    }
}

chatRecord::~chatRecord()
{
    delete ui;
}

void chatRecord::on_toolButton_2_clicked()
{
    this->close();
}

void chatRecord::on_toolButton_clicked()
{
    this->showMinimized();
}

void chatRecord::mousePressEvent(QMouseEvent *event)
{
    this->windowPos = this->pos();       // 获得部件当前位置
    this->mousePos = event->globalPos(); // 获得鼠标位置
    this->dPos = mousePos - windowPos;   // 移动后部件所在的位置
}

void chatRecord::mouseMoveEvent(QMouseEvent *event)
{
    this->move(event->globalPos() - this->dPos);
}
